<?php
session_start();

if (!session_is_registered(myusername)) {
	header("Location: index.php");
}

?>
<form>
<?php //Mandatory fields marked <span style="color: red">*</span><br/>?>
<table id="metaCreateSubTable">
<tr><td>Directory Number:</td><td><input type="text" id="directoryNumber"/></td></tr>
<tr><td>Persistent Profile:</td><td><select id="persistentProfile">
		<?php //TODO:  Grab this area from the DB, so changes can be done easier in future?>
		<option value="None">None</option>
		<option value="AMH1EC">AMH1EC</option>
		<option value="POL1EC">POL1EC</option>
		<option value="ROS1EC">ROS1EC</option>
		<option value="AMHPOTS">AMHPOTS</option>
		<option value="POLPOTS">POLPOTS</option>
		<option value="ROSPOTS">ROSPOTS</option>
		<option value="AMH1EC3P">AMH1EC3P</option>
		<option value="POL1EC3P">POL1EC3P</option>
		<option value="ROS1EC3P">ROS1EC3P</option>
		<option value="AMHPOTS3P">AMHPOTS3P</option>
		<option value="POLPOTS3P">POLPOTS3P</option>
		<option value="ROSPOTS3P">ROSPOTS3P</option>
		</select>
	</td></tr>
<tr><td>Number Status:</td><td><input type="text" id="numberStatus" value="Normal" readonly="readonly"/></td></tr>
<tr><td>Subscriber Group:</td><td><select id="subscriberGroup">
		<?php //TODO:  Grab this area from the DB, so changes can be done easier in future?>
		<option value="Amherst Local Calling Only">Amherst Local Calling Only</option>
		<option value="Polonia Local Calling Only">Polonia Local Calling Only</option>
		<option value="Rosholt Local Calling Only">Rosholt Local Calling Only</option>
		<option value="Subscribers in Amherst, WI">Subscribers in Amherst, WI</option>
		<option value="Payphones in Amherst, WI">Payphones in Amherst, WI</option>
		</select>
	</td></tr>
<tr><td>Call Agent Signaling Type:</td><td><select id="callAgentSignalingType" onChange="signalType(this.value)">
		<option value="Analog Line/T1 CAS">Analog Line/T1 CAS</option>
		<option value="SIP">SIP</option>
		<option value="None">None</option>
		</select>
	</td></tr>
<?php // If SIP is chosen we will reset and disable accessDevice and accessLineNumber use default settings??, if Analog Line is chose enable access device and line number?>
<tr><td>Access Device:</td><td><select id="accessDevice">
		<?php
		$a = snmp2_walk("172.18.1.50", "public", "1.2.826.0.1.1578918.6.1435.1.5");

		foreach($a as $accessDevice) {
			$accessDevice = preg_replace("/STRING: \"/", "", $accessDevice);
			$accessDevice = preg_replace("/\"/", "", $accessDevice);
			echo "<option value='$accessDevice'>$accessDevice</option>";
		}
		?>
		</select>
	</td></tr>
<tr><td>Access Line Number:</td><td><select id="accessLineNumber">
		<?php
			for( $i=1; $i < 49; $i++) {
				echo "<option value='$i'>$i</option>";
			}
		?>
		</select>
	</td></tr>
<tr><td>Long Distance Carrier:</td><td><input type="text" id="longDistanceCarrier" maxlength="4" /></td></tr>
<tr><td>Intra LATA Carrier:</td><td><input type="text" id="intraLATACarrier" maxlength="4" /></td></tr>
<tr><td>International Carrier:</td><td><input type="text" id="internationalCarrier" maxlength="4" /></td></tr>
</table>
<?php //<br/><br/>Call Services will be optional below:<br/><br/>?>
<br/>
<input type="reset" value="reset"/><input type="button" id="metaAddSubmit" value="Add"/><input type="checkbox" id="queryDebug"/>
</form>

<script type="text/javascript">

function signalType(value) {
	if (value == "Analog Line/T1 CAS") {
		document.getElementById('accessDevice').disabled = false;
		document.getElementById('accessLineNumber').disabled = false;
	}
	else if (value == "SIP" || value == "None") {
		document.getElementById('accessDevice').disabled = true;
		document.getElementById('accessLineNumber').disabled = true;
		document.getElementById('accessDevice').value = "";
		document.getElementById('accessLineNumber').value = "";
	}
	else {
		//Display nothing

	}
}

$('metaAddSubmit').addEvent('click', function(e){
                        if($('directoryNumber').value != ""){
                                var url = 'metaswitch/meta_create.php?';
                                url=url+'directoryNumber='+$('directoryNumber').value;
                                if ($('queryDebug').checked) {
                                        url=url+'&debug=True';
                                }
                                else {
                                        url=url+'&debug=False';
                                }
				url=url+'&persistentProfile='+$('persistentProfile').value;
				url=url+'&subscriberGroup='+$('subscriberGroup').value;
				url=url+'&callAgentSignalingType='+$('callAgentSignalingType').value;
				url=url+'&accessDevice='+$('accessDevice').value;
				url=url+'&accessLineNumber='+$('accessLineNumber').value;
				url=url+'&longDistanceCarrier='+$('longDistanceCarrier').value;
				url=url+'&intraLATACarrier='+$('intraLATACarrier').value;
				url=url+'&internationalCarrier='+$('internationalCarrier').value;
                                url=url+'&nocache='+Math.random();
                                MochaUI.updateContent({
                                        'element': $('panel1'),
                                        'loadMethod': 'xhr',
                                        'url': url,
                                        'title': 'Meta Query Results',
                                        'padding': { top: 8, right: 8, bottom: 8, left: 8 }
                                });
                                showSpinner();
                        }
                });


</script>
